home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / REALLOC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  669 b   |  24 lines

  1. /* realloc.c --- p. 139 */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <alloc.h>
  5. main()
  6. {
  7.     unsigned char *buffer;
  8.             /* Allocate room for string and check for NULL */
  9.     if( (buffer = (char *)malloc(10)) == NULL)
  10.     {
  11.         printf("allocation Failed. \n");
  12.         exit(0);
  13.     }
  14.     printf("Buffer allocated. Enter string to store: ");
  15.     gets(buffer);
  16.     printf("\nYou entered: %s\n", buffer);
  17.         /* Now enlarge the size of buffer and redisplay string */
  18.     if( (buffer = (char *)realloc((void *)buffer, 80)) == NULL )
  19.     {
  20.         printf("Reallocation Failed.\n");
  21.         exit(0);
  22.     }
  23.     printf("Buffer still contains: %s\n", buffer);
  24. }